package com.shopping.mall.core.module.order.mapper;

import com.shopping.mall.core.module.instrumentPanel.entity.HourOrderNum;
import com.shopping.mall.core.module.instrumentPanel.entity.OrderStateNum;
import com.shopping.mall.core.module.instrumentPanel.entity.PayNum;
import com.shopping.mall.core.module.order.entity.Order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.sql.Timestamp;
import java.util.List;

/**
 * <p>
 * OrderMapper 接口
 * </p>
 *
 * @author zzy
 * @since 2021-08-29
 */
@Mapper
public interface OrderMapper extends BaseMapper<Order> {

    @Select("select state,count(1) num from orders group by state")
    List<OrderStateNum> getStateNum();

    @Select("select ifnull(sum(total_price),0) total_price,ifnull(sum(freight_price),0) freight_price,ifnull(sum(goods_price),0) goods_price from orders")
    PayNum getPayNum();

    @Select("select ifnull(sum(total_price),0) from orders where pay_at > #{time}")
    double getTodayPrice(Timestamp time);

    @Select("SELECT DATE_FORMAT( create_at, '%Y-%m-%d %H:00:00' ) as time, COUNT(1) as num \n" +
            "FROM orders where create_at>#{time}" +
            "GROUP BY\n" +
            "\ttime \n" +
            "ORDER BY\n" +
            "\ttime")
    List<HourOrderNum> getHourOrderNum(Timestamp beforeDayTimestamp);
}
